﻿using SpyApp.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace SpyApp.Controllers
{
    public class CommonController : Controller
    {

        public UserRepository userRepository;
        List<Message> listMessage = new List<Message>();

        public CommonController()
        {
            this.userRepository = new UserRepository();
            for (int i = 0; i < 35; i++)
            {
                listMessage.Add(FakeMake.FakeMessage());
            }
        }

        [AllowAnonymous]
        public ActionResult Index(string sortOrder)
        {
            ViewBag.NumberSortParm = String.IsNullOrEmpty(sortOrder) ? "number_desc" : "number";
            ViewBag.ContextParm = sortOrder == "context" ? "context_desc" : "context";

            IEnumerable<Message> query = null;
            switch (sortOrder)
            {
                case "number":
                    query = listMessage.OrderBy(i => i.NumberSendReceive);
                    break;
                case "number_desc" :
                    query = listMessage.OrderByDescending(i => i.NumberSendReceive);
                    break;
                case "context":
                    query = listMessage.OrderBy(i => i.UserMessage);
                    break;
                case "context_desc":
                    query = listMessage.OrderByDescending(i => i.UserMessage);
                    break;
            }



            return View(listMessage);
        }

    }
}
